package com.weipai.demo.service.impl;


import com.weipai.demo.mapper.ImgMapper;
import com.weipai.demo.mapper.base.DImgBaseMapper;
import com.weipai.demo.mapper.base.DImgBusinessMapper;
import com.weipai.demo.model.DImgBase;
import com.weipai.demo.model.DImgBusiness;
import com.weipai.demo.model.bo.ImgBO;
import com.weipai.demo.model.vo.ImageVO;
import com.weipai.demo.service.IImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 图片接口实现类
 *
 * @author Jiahaonan
 * @create 2017-11-18 11:22
 **/
@Service()
public class ImageServiceImpl implements IImageService {
    @Autowired
    DImgBaseMapper imageBaseMapper;
    @Autowired
    DImgBusinessMapper imgBizMapper;
    @Autowired
    private ImgMapper imgMapper;

    @Override
    public Integer inserImageInfo(Integer productType,Integer imgType,String businessCode,String imgurls,String title,Integer index,String name) {
        DImgBase eImgBase = new DImgBase();
        eImgBase.setTitle(title);
        //TODO:登录人
        eImgBase.setCreateName(name);
        eImgBase.setUpdateName(name);
        eImgBase.setOssImgUrl(imgurls);
        eImgBase.setImgBase(imgurls);
        imageBaseMapper.insertSelective(eImgBase);
        //上传后 返回
        DImgBusiness eImgBusiness = new DImgBusiness();
        eImgBusiness.setImgId(eImgBase.getId());
        eImgBusiness.setCreateName(name);
        eImgBusiness.setUpdateName(name);
        eImgBusiness.setProductType(productType);
        eImgBusiness.setImgType(imgType);
        eImgBusiness.setImgIndex(index);
        eImgBusiness.setBusinessCode(businessCode);
        imgBizMapper.insertSelective(eImgBusiness);
        return eImgBase.getId();
    }

    @Override
    public int deleteImage(ImageVO imgInfo) {

        return 0;
    }

    @Override
    public List<ImgBO> searchImg(String businessCode, Integer productType, Integer imgType) {
        return imgMapper.searchImg(businessCode, productType, imgType);
    }

    @Override
    public void upImage(List<DImgBase> list) {
        imgMapper.upImage(list);
    }

    @Override
    public void upImageUrl(List<ImgBO> list) {
        imgMapper.upImageUrl(list);
    }
}
